'''
/*
 * @Author: wevsmy 
 * @Date: 2017-10-26 16:30:49 
 * @Last Modified by: wevsmy
 * @Last Modified time: 2017-10-26 18:51:35
 */
'''
from socket import *
#创建套接字
serverSocket = socket(AF_INET,SOCK_STREAM)
#重复使用绑定的信息
serverSocket.setsockopt(SOL_SOCKET,SO_REUSEADDR,1)
#绑定端口
serverSocket.bind(("",8080))
#最多支持的客户端
serverSocket.listen(5)

while True:
    print("-----主进程，等待客户端的到来-----")
    newSocket,destAdder = serverSocket.accept()
    print("-----主进程，接下来负责数据处理[%s]----"%str(destAdder))

    try:
        while True:
            recvData = newSocket.recv(1024).decode("gb2312")
            if len(recvData)>0:
                print("recv[%s]:%s"%(str(destAdder),recvData))
            else:
                print("[%s]客户端已经关闭"%str(destAdder))
                break
    finally:
        newSocket.close()
serverSocket.close()
